package com.lbn.monitor.app.history;

import com.free.framework.business.NetSubscriber;
import com.lbn.monitor.api.AppHost;
import com.lbn.monitor.api.model.Device;
import com.lbn.monitor.app.monitor.IMFListView;
import com.lbn.monitor.base.AppBasePresenter;

import java.util.List;

/**
 * @author 李炳南
 * @date 2017/3/29
 */
public class DeviceListPresenter extends AppBasePresenter<IDeviceListView> {

    public void list(final int page) {

        subscribeNetwork(AppHost.getApi().deviceList(page), new NetSubscriber<List<Device>>(getView(), false) {
            @Override
            public void onNext(List<Device> o) {
                IDeviceListView view = getView();
                if (null == view) {
                    return;
                }
                if (page == 1) {
                    view.refreshComplete(o);
                } else {
                    if (o.size() < 10) {
                        view.addMoreData(o, true);
                    }
                    view.addMoreData(o, false);
                }
            }
        });
    }
}
